<template>
  <page-layout>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div>
      <a-form @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="规格名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input style="width:100%;" placeholder="请输入规格名称" v-model="queryParam.specName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select placeholder="请输入项目名称" v-model="queryParam.productId"></a-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          </template>
          <a-col :md="6" :sm="8">
            <a-form-item>
              <a-button type="primary" @click="searchQuery()" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <vxe-grid
        id="crmSpecificationList"
        keep-source
        ref="vxeTable"
        :height="null"
        v-bind="options"
        @checkbox-change="onSelectChange"
        @checkbox-all="onSelectChange"
        @page-change="handlePageChange"
      >

      <template #action="{ row }">
        <template>
          <a @click="handleEdit(row)" >编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(row)">详情</a>
                </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
      </template>
    </vxe-grid>
    </div>
    <!-- table区域-end -->
    <CrmSpecificationModal ref="modalForm" @ok="modalFormOk"></CrmSpecificationModal>
  </a-card>
  </page-layout>
</template>

<script>
import PageLayout from '@/layouts/PageLayout'
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import { deleteAction } from '@/services/manage'
import CrmSpecificationModal from './modules/CrmSpecificationModal.vue'

export default {
  name: "crmSpecificationList",
  components: {
    PageLayout,
    CrmSpecificationModal,
  },
  mixins: [VxeTableMixin],
  data() {
    return {
      columns: [
        {
          type: 'seq',
          width: 60,
          field: 'seq'
        },
        {
          title: '规格名称',
          field: 'specName'
        },
        {
          title:'项目名称',
          align:"center",
          field: 'productId',
          width: 200,
          formatter: 'dictText'
        },
        {
          title: '版本',
          field: 'specVersion'
        },
        {
          title: '版本提交时间',
          field: 'submitTime'
        },
        {
          title: '创建人',
          field: 'createBy',
          formatter: 'dictText'
        },
        {
          title: '创建日期',
          field: 'createTime'
        },
        {
          title: '更新日期',
          field: 'updateTime'
        },
        {
          title: '操作',
          field: 'action',
          align:"center",
          fixed:"right",
          width:200,
          slots: { default: 'action' }
        }
      ],
      url: {
        list: '/specification/list',
        delete: '/specification/delete/',
        deleteBatch: '/specification/deleteBatch',
        exportXlsUrl: '/specification/exportXls',
        importExcelUrl: '/specification/importExcel'
      },
      // 查询参数
      queryParam: {},
      selectedRowKeys: [],
      selectedRows: [],
      toggleSearchStatus: false
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  created() {
  },
  methods: {
    handleDelete: function(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      deleteAction(that.url.delete, { "id": id }).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
  }
}
</script>
